package com.xyebank.ledger.service.sjdzadd.dataProvider.apply;


import com.xyebank.ledger.service.common.DataProvider;
import com.xyebank.ledger.util.DateUtil;
import com.xyebank.ledger.vo.deal.ZADDSjdCashApplyVo;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class ZADDSjdCashApplyProvider implements DataProvider<ZADDSjdCashApplyVo> {

    @Autowired
    private ZADDSjdCashApplyMapper zaddSjdCashApplyMapper;

    @Override
    public List<ZADDSjdCashApplyVo> get(Integer fromIdx, Integer tarNum) {
        List<ZADDSjdCashApply> result = zaddSjdCashApplyMapper.selectByPaging(fromIdx, tarNum);
        List<ZADDSjdCashApplyVo> list = convert2Vo(result);
        return list;
    }


    @Override
    public List<ZADDSjdCashApplyVo> get(Date dateStart, Date dateEnd, Integer fromIdx, Integer tarNum) {
        List<ZADDSjdCashApply> result = zaddSjdCashApplyMapper.selectByPeriod(DateUtil.getFormatDate(dateStart), DateUtil.getFormatDate(dateEnd), fromIdx, tarNum);
        List<ZADDSjdCashApplyVo> list = convert2Vo(result);
        return list;
    }


    @Override
    public Integer count(Date timeStart, Date timeEnd) {
        Integer count = zaddSjdCashApplyMapper.selectPeriodCount(DateUtil.getFormatDate(timeStart), DateUtil.getFormatDate(timeEnd));
        return count;
    }


    private List<ZADDSjdCashApplyVo> convert2Vo(List<ZADDSjdCashApply> result) {
        List<ZADDSjdCashApplyVo> list = new ArrayList<ZADDSjdCashApplyVo>();
        for (int i = 0; i < result.size(); i++) {
        	ZADDSjdCashApplyVo vo = new ZADDSjdCashApplyVo();
            BeanUtils.copyProperties(result.get(i), vo);
            list.add(vo);
        }
        return list;
    }

}
